package cz.spock.cms.entity;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.Id;

import com.googlecode.objectify.Key;
import com.googlecode.objectify.annotation.Unindexed;

import cz.spock.cms.entity.content.Field;
import cz.spock.cms.template.entity.TemplateSource;

/**
 * Node is main data holder for description of web page.
 * 
 * Each web page (project) has root node (homepage).
 * 
 * Each Node can have parent Node (or more) and childs.
 * Recommendation is that each Node has ONE parent, so that tree-like data structure is used to describe web page.
 * 
 * In addition, each Node can has content (as each single page). Content is represented by Fields (text field, number field, date field, video field...).
 * Content Fields can be grouped in Nodes, so better logical structure can be created. So Node can represent whole page or just fragment of page, or both.
 * 
 * Node can have URL, also in case when Node is part of another Node.
 * 
 * Nodes and Fields are able to describe whole structure of web page.
 * Created data structure is something like tree or graph with 2 dimensions - first describes parent/child relationships, second describes content of single page.
 * - second dimension is then used by free marker template engine
 * - first can be used for creating menus, navigations... 
 * 
 * @author miso
 *
 */
/**
 * TODO something for static nodes not to create html all the time... save generated html page for static nodes
 */
@Entity
public class Node {
    
    @Id
    private Long id;
    
    private String label; // is supposed to be human readable URI

    private String url; // is supposed to be url accessible via http 
    
    private Key<Project> project;
    @Unindexed
    private String description;
    @Unindexed
    private List<Key<Node>> childs;
    @Unindexed
    private List<Key<Node>> parents;
    @Unindexed
    private List<Key<Node>> contentNodes;
    @Unindexed
    private List<Key<Field>> contentFields;
    
    private Key<TemplateSource> template;
    @Unindexed
    private Key<CSS> css;
    
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public List<Key<Node>> getChilds() {
        return childs;
    }

    public void setChilds(List<Key<Node>> childs) {
        this.childs = childs;
    }

    public List<Key<Node>> getContentNodes() {
        return contentNodes;
    }

    public void setContentNodes(List<Key<Node>> contentNodes) {
        this.contentNodes = contentNodes;
    }

    public List<Key<Field>> getContentFields() {
        return contentFields;
    }

    public void setContentFields(List<Key<Field>> contentFields) {
        this.contentFields = contentFields;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public List<Key<Node>> getParents() {
        return parents;
    }

    public void setParents(List<Key<Node>> parents) {
        this.parents = parents;
    }

    public Key<Project> getProject() {
        return project;
    }

    public void setProject(Key<Project> project) {
        this.project = project;
    }

    public Key<TemplateSource> getTemplate() {
        return template;
    }

    public void setTemplate(Key<TemplateSource> template) {
        this.template = template;
    }

    public Key<CSS> getCss() {
        return css;
    }

    public void setCss(Key<CSS> css) {
        this.css = css;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

}
